package leetcode.leetcode_53;

class Solution {
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int preNum = 0;
        int maxSum = Integer.MIN_VALUE;
        int minSum = 0;
        for (int i : nums){
            preNum += i;
            maxSum = Math.max(preNum-minSum,maxSum);
            minSum = Math.min(preNum,minSum);
        }
        return maxSum;
    }
}